﻿using System;

namespace Delegatedemo2
{
    public delegate int PerformCalc(int x, int y);
   class Program
    {
        static void Main(string[] args)
        {
            Calculator calc = new Calculator();
            PerformCalc del = calc.CalcDelegate;
            int result = del(32, 29);

            Console.WriteLine("result: {0}", result);

        }
    }

    internal class Calculator
    {
        PerformCalc perfCalc;

        public Calculator()//通过构造函数注入委托
        {
            perfCalc = CalculateProduct;
        }

        private int CalculateProduct(int x, int y)
        {
            return x + y;
        }

        public PerformCalc CalcDelegate { get {return perfCalc;} }//通过属性获得委托对象
    }
}